#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 2e5 + 10;
int arr[N];
int n, m;
struct Node
{
	int l, r, mv;
}tree[N * 4];
void pushup(int u)
{
	tree[u].mv = max(tree[u << 1].mv, tree[u << 1 | 1].mv);
}

void build(int u, int l, int r)
{
	if (l == r) {
		tree[u] = { l,r,arr[l] };
	}
	else {
		tree[u] = { l,r };
		int mid = l + r >> 1;
		build(u << 1, l, mid);
		build(u << 1 | 1, mid + 1, r);
		pushup(u);
	}
}
int query(int u, int l, int r)
{
	if (tree[u].l >= l && tree[u].r <= r) {
		return tree[u].mv;
	}
	int ans = 0;
	int mid = tree[u].l + tree[u].r >> 1;
	if (l <= mid) {
		ans = max(ans, query(u << 1, l, r));
	}
	if (r > mid) {
		ans = max(ans, query(u << 1 | 1, l, r));
	}
	return ans;
}
void modify(int u, int l, int v)
{
	if (tree[u].l == tree[u].r) {
		tree[u].mv = v;
	}
	else {
		int mid = tree[u].l + tree[u].r >> 1;
		if (l <= mid) {
			modify(u << 1, l, v);
		}
		else {
			modify(u << 1 | 1, l, v);
		}
		pushup(u);
	}
}
int main()
{
	while (scanf("%d%d", &n, &m) != EOF) {
		for (int i = 1; i <= n; i++) {
			scanf("%d", &arr[i]);
		}
		build(1, 1, n);
		while (m--) {
			char op[2];
			cin >> op;
			if (op[0] == 'U') {
				int a, b;
				scanf("%d%d", &a, &b);
				modify(1, a, b);
			}
			else {
				int a, b;
				scanf("%d%d", &a, &b);
				cout << query(1, a, b) << endl;
			}
		}
	}
	return 0;
}
